<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AJAX</title>
    <script src="https://code.jquery.com/jquery-3.0.0.min.js"></script>
</head>
<body>
    <button>USER</button>
</body>
</html>

<script>
    $.ajaxSetup({
        complete:function(xhr,status){
            //拦截器实现超时跳转到登录页面
            let win = window;
            // 通过xhr取得响应头
            let REDIRECT = xhr.getResponseHeader("REDIRECT");
            //如果响应头中包含 REDIRECT 则说明是拦截器返回的需要重定向的请求
            if (REDIRECT === "REDIRECT")
            {
                while (win !== win.top)
                {
                    win = win.top;
                }
                win.location.href = xhr.getResponseHeader("CONTEXTPATH");
            }
        }
    });
    $("button").click(function(){
        $.get("/page/user", function(result){
            $("div").html(result);
        });
    });
</script>